<template>
  <div>
    <div class="top">
      <van-nav-bar
        title="确定订单"
        left-text=""
        left-arrow
        @click-left="onClickLeft"
      />
    </div>
    <div class="main">
      <van-contact-card
        type="edit"
        :name="currentContact.name"
        :tel="currentContact.tel"
        @click="onEdit"
      />
      <van-card
        v-for="item in getlist"
        :key="item.proid"
        :num="item.num"
        :price="item.originprice"
        :desc="item.proname"
        :title="item.proname"
        :thumb="item.img1"
      />
      <!-- <button @click="onclick">点击</button> -->
    </div>
    <div class="">
      <van-submit-bar :price="num" button-text="结算" @submit="onSubmit" />
    </div>
  </div>
</template>

<script>
import { ConfirmOrder, getMorenAddress, DelOrder } from "@/request/api";
import Vue from 'vue';
import { Dialog } from 'vant';

// 全局注册
Vue.use(Dialog);
export default {
  data() {
    return {
      currentContact: {
        name: "张三",
        tel: "13000000000",
      },
      getlist: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onEdit() {
      this.$router.push("/order/addaddress");
    },
    onSubmit() {
      // 删除支付时选中数据
    
      DelOrder({
        token: localStorage.getItem("token"),
        userid: localStorage.getItem("userid"),
      }).then((res) => {
        console.log(res);
        Dialog.alert({
          title: "确定结算",
        }).then(() => {
         this.$router.push("/")
        });
      });
    },
  },
  created() {
    
    ConfirmOrder({
      token: localStorage.getItem("token"),
      userid: localStorage.getItem("userid"),
      time: localStorage.getItem("time"),
    }).then((res) => {
      console.log("res");
      console.log(res.data.data);
      this.getlist = res.data.data;
      
    });
    getMorenAddress({
      userid: localStorage.getItem("userid"),
      token: localStorage.getItem("token"),
    }).then((res) => {
      console.log(res.data.data);
      this.currentContact.name = res.data.name;
      this.currentContact.tel = res.data.tel;
    });
  },
  computed: {
    num: {
      set(val) {
        console.log(val);
      },
      get() {
        var num = 0;
        this.getlist.forEach((item) => {
          num += item.originprice * item.num * 100;
        });
        return num;
      },
    },
  },
};
</script>

<style>
</style>